﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Xml;

/// <summary>
/// Summary description for SportHelper
/// </summary>
public class SportHelper
{

    public static List<string> GetSports()
    {
        List<string> result = new List<string>();

        foreach (KeyValuePair<string, string> item in SportsDic)
        {
            result.Add(item.Key);
        }
        return result;
    }

    private static Dictionary<string, string> sportsDic;

    public static Dictionary<string, string> SportsDic
    {
        get
        {
            if (sportsDic == null)
            {
                sportsDic = LoadSports();
            }
            return sportsDic;
        }
    }


    private static Dictionary<string, string> LoadSports()
    {
        Dictionary<string, string> result = new Dictionary<string, string>(); 
        XmlDocument sportsDoc = new XmlDocument();
        string sportsFile = HttpContext.Current.Server.MapPath("Sports.xml");
        sportsDoc.Load(sportsFile);
        foreach (XmlNode item in sportsDoc.ChildNodes[0].ChildNodes)
        {
            string sport = item.Attributes["name"].InnerText;


            if (!result.ContainsKey(sport))
            {
                result.Add(sport, "1");
            }

        }
        return result;
    }

   
}
